//https://leetcode.cn/problems/binary-tree-postorder-traversal/
package codeRandomThoughts.Test145二叉树的后序遍历;

import codeRandomThoughts.utils.TreeNode;

import java.util.*;

//后序遍历递归
public class Solution2 {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        postOrder(root, result);
        return result;
    }

    public void postOrder(TreeNode root, List<Integer> result) {
        if (root == null) {
            return;
        }

        postOrder(root.left, result);
        postOrder(root.right, result);
        result.add(root.val);
    }
}